import { createApp } from 'vue'
import App from './App.vue'
//import LoginView from './views/LoginView.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import axios from './util/axios'
//import 'element-plus/theme-chalk/index.css'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import {initMenu} from './util/menu'
import zhCn from 'element-plus/es/locale/lang/zh-cn'


const app = createApp(App);
app.config.isStrict = false;
app.config.globalProperties.$axios=axios;
app.use(store).use(router).use(ElementPlus, {
  locale: zhCn,
}).mount('#app');

//app.config.isStrict = false;




// createApp(LoginView).use(store).use(router).use(ElementPlus).mount('#app');




//app= createApp(LoginView);
for (const name in ElementPlusIconsVue) {
  app.component(name, ElementPlusIconsVue[name])
}


router.beforeEach((to, from, next) => {
  if(to.path =='/'){
    console.log("我到了to.path =='/'的环节");
    next();
  }else{
    //console.log("登录前判断1"+store.getters.isLogin);
    //console.log("登录前判断2"+sessionStorage.getItem("user"));
    if(store.getters.isLogin && window.sessionStorage.getItem("user")!=null){
      store.commit('setUser',JSON.parse(window.sessionStorage.getItem("user")));
      //console.log("用户名判断"+JSON.parse(window.sessionStorage.getItem("user")).userName);
      let username=JSON.parse(window.sessionStorage.getItem("user")).userName;
      console.log("获取用户名："+username);
      initMenu(router,store);
      next();
    }else{
      confirm("您还未登录，请先登录");
      //next({path:'/',query:{redirect:to.path}});
      next('/');
    }
  }
});